package com.yj.lottery_system.dao.mapper;

import com.yj.lottery_system.dao.dataObject.PrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PrizeMapper {
    @Insert("insert into prize (name, image_url, price, description) values" +
            " (#{name},#{imageUrl},#{price},#{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insert(PrizeDO prizeDO);

    /**
     * 查询奖品总数
     * @return
     */
    @Select("select count(1) from prize")
    int count();

    /**
     * 查询当前页面的奖品列表
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("select * from prize order by id desc limit ${offset}, #{pageSize}")
    List<PrizeDO> selectPrizeList(@Param("offset") Integer offset,@Param("pageSize") Integer pageSize);
    /**
     * 根据传入的id列表查询列表中存在数据库的值
     * @param ids id列表
     * @return id列表中存在数据库的id值
     */
    @Select("<script> " +
            "select id from prize  " +
            "where id in " +
            "<foreach item = 'item' collection='items' open='(' separator=',' close=')' > " +
            " #{item} " +
            "</foreach>" +
            "</script>")
    List<Long> selectExitsByIds(@Param("items") List<Long> ids);
    /**
     * 根据前端传入的id列表查询列表中存在数据库的奖品信息
     * @param prizeIds id列表
     * @return id列表中对应的数据库完整字段信息
     */
    @Select("<script> " +
            "select * from prize  " +
            "where id in " +
            "<foreach item = 'item' collection='items' open='(' separator=',' close=')' > " +
            " #{item} " +
            "</foreach>" +
            "</script>")
    List<PrizeDO> batchSelectByIds(@Param("items") List<Long> prizeIds);

    /**
     * 根据奖品id查奖品信息
     * @param id
     * @return
     */
    @Select("select * from prize where id = #{id}")
    PrizeDO selectById(@Param("id")Long id);
}
